import Vue from 'vue'
import App from './App.vue'
import router from './router'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import './HomeIndex.css'
import 'material-design-icons-iconfont/dist/material-design-icons.css'

import moment from 'moment';
import { saveAs } from 'file-saver';
import * as XLSX from 'xlsx';


Vue.prototype.$moment = moment;    // 设置全局的moment

Vue.config.productionTip = false

Vue.prototype.$XLSX = XLSX;
Vue.prototype.$saveAs = saveAs;

import axios from 'axios'  //引入axios
//用axios的拦截器,加上请求头
axios.interceptors.request.use(
  config => {
    let jwt = localStorage.getItem("authToken");
    if (jwt) {
      config.headers.authToken = jwt;
    }
    return config;
  }
)

Vue.prototype.$axios = axios //把axios配置全局的变量，变量名是$axios

//配置一个axois响应拦截器
axios.interceptors.response.use(response => {
  // 对响应数据做些什么
  if (response.data.code == 40004) {
    // 如果code是40002，提示错误信息
    new Vue().$message.error(response.data.msg)
    return response;
  } else {
    // 如果code不是40004，直接返回response
    return response;
  }
});
Vue.use(ElementUI);


new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
